// 找出一个数组中所有的逆序对
const fn = (arr: Array<number>) => {
    return process(arr,0,arr.length-1)
}
const process = (arr: Array<number>,L:number,R:number):number => {
    if(L == R) return 0
    let mid = L + ((R-L) >>1)
    return process(arr,L,mid) +
    process(arr,mid+1,R) +
    merge(arr,L,mid,R)
}
const merge = (arr:Array<number>,L:number,M:number,R:number):number =>{
    let help:Array<number> = []
    let i = 0
    let p1 = L
    let p2 = M+1
    let num = 0
    while (p1 <= M && p2 <= R){
        num += arr[p1] > arr[p2] ? M - p1 +1 : 0
        help[i++] = arr[p1] <= arr[p2] ? arr[p1++] :arr[p2++]
    }
    while(p1 <= M){
        help[i++] = arr[p1++]
    }
    while(p2 <= R){
        help[i++] = arr[p2++]
    }
    for(i = 0; i < help.length; i++){
        arr[L+i] = help[i]
    }
    console.log(num,'num')
    return num
}
console.log(fn([3,2,4,5,0]))
export default fn